<template>
  <div class="app-container">
    <div class="filter-container">
      <el-select v-model="catalog1Val" placeholder="一级分类" style="width: 110px" class="filter-item" @change="changeCatalog1">
        <el-option v-for="item in catalog1" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>

      <el-select v-model="catalog2Val" placeholder="二级分类" style="width: 110px" class="filter-item" @change="changeCatalog2">
        <el-option v-for="item in catalog2" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>

      <el-select v-model="catalog3Val" placeholder="三级分类" style="width: 110px" class="filter-item" @change="changeCatalog3">
        <el-option v-for="item in catalog3" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
    </div>
    <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="addAttributes">
      新增平台属性
    </el-button>
  </div>
</template>

<script>
import { getCatalog1, getCatalog2, getCatalog3 } from '@/api/catalog'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
  name: 'Attributes',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      catalog1: null,
      catalog2: null,
      catalog3: null,
      catalog1Val: '',
      catalog2Val: '',
      catalog3Val: ''
    }
  },
  created() {
    this.getCatalog1()
  },
  methods: {
    getCatalog1() {
      this.listLoading = true
      getCatalog1().then(response => {
        this.catalog1 = response.data
        this.listLoading = false
      })
    },

    changeCatalog1(e) {
      console.log('改变c1', e)
      this.listLoading = true
      getCatalog2(e).then(response => {
        this.catalog2 = response.data
        this.catalog3 = null
        this.catalog2Val = ''
        this.catalog3Val = ''
        console.log('可以了', response)
        this.listLoading = false
      })
    },

    changeCatalog2(e) {
      console.log('改变c2', e)
      this.listLoading = true
      getCatalog3(e).then(response => {
        this.catalog3 = response.data
        this.catalog3Val = ''
        console.log('可以了', response)
        this.listLoading = false
      })
    },

    changeCatalog3(e) {
      console.log('改变c3', e)
      // this.listLoading = true
      // getCatalog3(cat2Id).then(response => {
      //   this.catalog3 = response.data
      //   console.log('可以了', response)
      //   this.listLoading = false
      // })
    },

    addAttributes() {
      console.log('新增平台属性')
    }
  }
}
</script>
